# -*- coding: utf-8 -*-
#===================================================
# @Time : 2021/3/15 13:33                           
# @Author : weni09                                  
# @File : response.py
#===================================================
from fastapi.responses import JSONResponse
from fastapi.encoders import jsonable_encoder
# class ApiResponse(JSONResponse):
#     def __init__(self,code = "success",
#                  msg = "it\'s ok",
#                  result = None
#                  ):
#         self.content={
#             'code': 'failed',
#             'message': 'it\'s bad.'
#         } if result and isinstance(result,dict) and result.get('error') else {
#             'code': code,
#             'message': msg
#         }
#         if result is not None:
#             self.content.update(dict(result=result))
#
#         super().__init__(content=jsonable_encoder(self.content))

from typing import Dict,Sequence,Optional,Union

from pydantic import BaseModel
class ApiResponseBase(BaseModel):
    code: Optional[str] = "success"
    msg: Optional[str] = "it\'s ok"
    data: Union[Dict, Sequence[Dict]] = None

class ApiResponse(ApiResponseBase):
    total: Optional[int]=0

class ApiResponseAuth(ApiResponse):
    user_id: Optional[int]=0

class ApiResponseBaseAuth(ApiResponseBase):
    user_id: Optional[int]=0